load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
    name = "go_default_library",
    srcs = ["main.go"],
    importpath = "k8s.io/kops/cmd/kube-apiserver-healthcheck",
    visibility = ["//visibility:private"],
    deps = [
        "//pkg/wellknownports:go_default_library",
        "//vendor/k8s.io/klog/v2:go_default_library",
    ],
)

go_test(
    name = "go_default_test",
    srcs = ["proxy_test.go"],
    embed = [":go_default_library"],
)

go_binary(
    name = "kube-apiserver-healthcheck",
    out = select({
        "@io_bazel_rules_go//go/platform:linux_amd64": "linux-amd64/kube-apiserver-healthcheck",
        "@io_bazel_rules_go//go/platform:linux_arm64": "linux-arm64/kube-apiserver-healthcheck",
        "@io_bazel_rules_go//go/platform:darwin_amd64": "darwin-amd64/kube-apiserver-healthcheck",
    }),
    embed = [":go_default_library"],
    visibility = ["//visibility:public"],
)

load(
    "@io_bazel_rules_docker//container:container.bzl",
    "container_bundle",
    "container_image",
    "container_push",
)

ARCH = [
    "amd64",
    "arm64",
]

[container_image(
    name = "image-%s" % arch,
    architecture = arch,
    base = "@distroless_base_%s//image" % arch,
    cmd = ["/kube-apiserver-healthcheck"],
    files = [
        "//cmd/kube-apiserver-healthcheck",
    ],
    stamp = True,
    user = "10012",
) for arch in ARCH]

[container_push(
    name = "push-image-%s" % arch,
    format = "Docker",
    image = ":image-%s" % arch,
    registry = "{STABLE_DOCKER_REGISTRY}",
    repository = "{STABLE_DOCKER_IMAGE_PREFIX}kube-apiserver-healthcheck",
    tag = "{STABLE_KUBE_APISERVER_HEALTHCHECK_TAG}-%s" % arch,
) for arch in ARCH]

[container_bundle(
    name = "image-bundle-%s" % arch,
    images = {
        "{STABLE_DOCKER_IMAGE_PREFIX}kube-apiserver-healthcheck:{STABLE_KUBE_APISERVER_HEALTHCHECK_TAG}": "image-%s" % arch,
    },
) for arch in ARCH]

load("//tools:gzip.bzl", "gzip")

[gzip(
    name = "image-bundle-%s.tar.gz" % arch,
    src = "image-bundle-%s.tar" % arch,
) for arch in ARCH]

load("//tools:hashes.bzl", "hashes")

[hashes(
    name = "image-bundle-%s.tar.gz.hashes" % arch,
    src = "image-bundle-%s.tar.gz" % arch,
) for arch in ARCH]
